﻿// 两种邮件列表模式的切换
function MLMD() {
	if(!arguments[0]) return;
	if(arguments[0].include('mail')) {
		isConferenceMode = false;
		// 清掉普通模式下的缓存
		mailList.clearListCache();
		mailList.refreshListFlag = true;
	} else {
		isConferenceMode = true;
		mailConference.clearListCache();
	}
	folder_detail({}, function(ret) {
		try {
			FolderList = ret.folders;
		} catch(e) {}
		try {
			mailConference.F = ret;
		} catch(e) {}
		ML(function() {
			var params = {
				isconference: isConferenceMode
			};
			profile_set(params, function(ret) {
				PROFILE.isconference = isConferenceMode;
			});
		});
	});
}


// 判断两种模式下的maillist
function ML(callback) {
	if(isConferenceMode) {
		mailConference.getMailList(mailList.currentFolder, mailList._currentPage, callback);
	} else {
		mailList.getMailPage(mailList.currentFolder, mailList._currentPage, null, callback);
	}
}

/***************************  mail list的类整理到此结束（下面的提示层代码整理将作为单独的函数独立出来）  ****************************/



//quzhi 20090702 设置容量提醒层
function showFOLDER(){
	var folderDate=FOLDER.evalJSON();
	// var tmpArray=foldersListASC(folderDate.folders);
	var tmpArray = folderDate.folders;
	var boxTemplate=['<img id="close" src="'+MailConst.ALL+'/closebox.png" onclick="_dialog.close()"   title="Close this window" >',
	                 				  '<div class="box_header">',
	                 				  '<div style="padding-top:10px;text-indent:24px;padding-left:20px;width:90%;">您已经使用了邮箱容量的95%以上，需要尽快清理无用邮件以保证正常信件能被接收下来：</div>',
	                 				  '<table class="box_body"  width="100%" border="0" cellspacing="0" cellpadding="0" >'].join('');

	var tmpArray1 = [], tmpArray2 = [], tmpArray3 = [];
	//排序显示文件夹列表,按系统文件夹,自定义文件夹,代收排序
	tmpArray.each(function(folder) {
		//系统
		if(folder.folder_id<6){
			tmpArray1.push(folder);
		}
		//自定义
		if(folder.folder_id>16&&folder.name.indexOf('@')==-1){
			tmpArray2.push(folder);
		}
		//代收
		if(folder.folder_id>16&&folder.name.indexOf('@')!=-1){
			tmpArray3.push(folder);
		}
	});
	var folderArray = tmpArray1.concat(tmpArray2.concat(tmpArray3));
	
	folderArray.each(function(folder){
		if(folder.folder_id==4||folder.folder_id==5){
			boxTemplate+=['<tr id="space_'+folder.folder_id+'">','<td><a href="javascript:" hidefocus="true" onmousedown="changePanel(\'mailList\', '+folder.folder_id+');" />'+folder.name+'</a></td>','<td>'+folder.total+'封</td>','<td>'+strfsize(folder.size)+'</td>','<td><a href="javascript:" hidefocus="true" onmousedown="changePanel(\'mailList\', '+folder.folder_id+');" />【查看】</a></td>','<td id="clearBox_'+folder.folder_id+'"><a href="javascript:" hidefocus="true" onmousedown="clearBoxTrash('+folder.folder_id+');" >【清空】</a></td>','</tr>'].join('');
		}else{
			boxTemplate+=['<tr id="space_'+folder.folder_id+'">','<td><a href="javascript:" hidefocus="true" onmousedown="changePanel(\'mailList\', '+folder.folder_id+');" />'+folder.name+'</a></td>','<td>'+folder.total+'封</td>','<td>'+strfsize(folder.size)+'</td>','<td><a href="javascript:" hidefocus="true" onmousedown="changePanel(\'mailList\', '+folder.folder_id+');" />【查看】</a></td>','</tr>'].join('');
		}
	});

	boxTemplate+=['</table>','<div style="padding-top:10px;text-indent:24px;">邮箱容量'+strfsize(mailContentTotalSize)+' ,当前占用'+strfsize(folderDate.totalSize)+'</div>'].join('');
	_dialog.custom({title:'容量提示',html:boxTemplate,style:{width:'500px'}});
}

//quzhi 20090702 设置容量提醒层
function clearBoxTrash(_folder_id) {
	$('clearBox_'+_folder_id).innerHTML='<img src="'+MailConst.ALL+'/loader2.gif" width="16" height="16" align="absmiddle" style="margin-left:3px;"/>正在清空邮件';
	var params = {
		folderId4Test : _folder_id,
		dest_id : -1,
		is_folder : true,
		folder_id : _folder_id
	};
	mail_move(params, _clearBoxTrashCallBack.bind(clearTrash, _folder_id));
}

//quzhi 20090702 设置容量提醒层
function _clearBoxTrashCallBack(_folder_id,ret){
	var _folderName={'4':'已删除','5':'垃圾邮件'};
	if(ret.is_success){
		setTimeout(function() {
			$('clearBox_'+_folder_id).innerHTML='&nbsp;已清空';
			setTimeout(function() {
				var html=['<td><a href="javascript:" hidefocus="true" onmousedown="changePanel(\'mailList\', '+_folder_id+');" />'+_folderName[_folder_id]+'</a></td>','<td>0封</td>','<td>0</td>','<td><a href="javascript:" hidefocus="true" onmousedown="changePanel(\'mailList\', '+_folder_id+');" />【查看】</a></td>','<td id="clearBox_'+_folder_id+'"><a href="javascript:" hidefocus="true" onmousedown="clearBoxTrash('+_folder_id+');" >【清空】</a></td>'].join('');
				$('space_'+_folder_id).update(html);
			},1000);
		}, 2000);
	}
}




/**************************** 重写maillist为类的结构 *****************************/

var MailList = Class.create();
MailList.prototype = {
	initialize: function() {
		// 当前文件夹ID
		this.currentFolder = 0;
		// 当前页面（第几页）
		this.currentPage = 0;
		this._currentPage = 0;
		this.starLevel = 0; //gaoyanxia add 20080916 星标 0：普通，1：重要，2：完成
		this.currentTotalCount = 0;
		this.pagecounttmp = 1;
		this.isConferenceMode = PROFILE.isconference ? PROFILE.isconference : false;
		// 控制信件列表的cache
		this.mailListCache = {
			inbox1: [],
			inbox5: []
		};
		// 用户点击列表页面的时候，记录用户点击的文件夹
		this.currentFolderCache = 0;
		// 记录用户点击的页面
		this.currentPageCache = 0;
		// 记录当前页面容量
		this.currentCountCache = 0;
		// 是否刷新列表界面内容的标记
		this.refreshListFlag = false;
		// 记录列表页面滚动的位置，用户读完信回来还能到原先的位置
		this.listScrollPos = 0;
		// 记录的timer
		this.list_scroll_pos_timer = null;
		// 获取列表页面的时候是否增加有callback函数
		this.mailCallbackFunc = null;
		this._is_rsh;
		// 获得列表页面选中的项
		this.GetSMails = null;
		// 是否排序
		this._sort = {};
		this._order = {
			sender: 0,
			subject: 0,
			date: 0,
			star: 0
		};
		this._order_name = 'date';
		// 多彩星标
		this.multiStar = {
			timer: null,
        	color: ['#4c4c4c', '#ff6600', '#28593E', '#005BA2', '#BD1000', '#7733AA'],
        	star: ['icon_star0', 'icon_star1', 'icon_star2', 'icon_star3', 'icon_star4', 'icon_star5'],
        	id: 0,
        	title : ['普通', '重要', '关注', '完成', '后续工作', '有疑问']
		};
		// 直邮颜色
		this.sysMailColor = ['#000000', '#993300', '#333300', '#003300', '#003366', '#000080', '#333399', '#333333', '#800000', '#FF6600', '#808000', '#008000', '#008080', '#0000FF', '#666699', '#808080', '#FF0000', '#FF9900', '#99CC00', '#339966', '#33CCCC', '#3366FF', '#800080', '#999999'];
	},
	// 清空缓存
	clearListCache: function() {
		try {
			for (var key in this.mailListCache) {
				this.mailListCache[key] = [];
			}
		} catch(e) {}
	},
	// 清空排序
	resetOrder: function() {
		if(this._order_name == 'date' && this._order.date == 0) return false;
		this._sort = {};
		this._order = {
			sender: 0,
			subject: 0,
			date: 0,
			star: 0
		};
		this._order_name = 'date';
		this.refreshListFlag = true;
		this.mailListCache['inbox' + this.currentFolder] = [];
	},
    initEvent: function() {
		var self = this;
        var _tmp_dl = [{
            name: 'firstpage',
            exec: function(){
                self.getMailPage(self.currentFolder, 0);
            }
        }, {
            name: 'prevpage',
            exec: function(){
                self.getMailPage(self.currentFolder, (self.currentPage - 1));
            }
        }, {
            name: 'nextpage',
            exec: function(){
                self.getMailPage(self.currentFolder, (self.currentPage + 1));
            }
        }, {
            name: 'endpage',
            exec: function(){
                self.getMailPage(self.currentFolder, (self.pagecounttmp - 1));
            }
        }, {
            name: 's_delete',
            exec: function(){
                self.permanentDeleteMailItems();
            }
        }, {
            name: 's_delt',
            exec: function(){
                self.deleteMailItems();
            }
        }, {
            name: 's_undelt',
            exec: function(){
                self.unDeleteMailItems();
            }
        }, {
            name: 's_spam',
            exec: function(){
                self.spamMailItems();
				jsoplog.ucCapture('spammail');
            }
        }, {
            name: 's_unspam',
            exec: function(){
                self.moveMailTo(1);
            }
        }, {
			name: 's_move',
			exec: function(EL, event) {
				var l = self.getMailListFolderlist();
				if(l.length == 0) {
					Tips.show('没有可移至的文件夹', 3);
					return false;
				}
				menu.showMenu(EL, DOM.sohuMailMain, l, 'menu', true, null, event);
			}
		}, {
			name: 's_mark_unread',
			exec: function(EL, event) {
				var l = self.getMarkReadList();
				menu.showMenu(EL, DOM.sohuMailMain, l, 'menu', true, null, event);
			}
		}, {
            name: 's_clear_trash',
            exec: function(){
                self.clearTrash(self.currentFolder)
            }
        }];
		
		/*
        Event.observe(DOM.mailList, 'mousedown', function(event){
			if(!Event.isLeftClick(event)) return false;
            if (isConferenceMode) return false;
            var EL = event.target;
            try {
                var mid = EL.mid ? EL.mid : EL.getAttribute('mid');
                if (mid) {
                    mailRead.getMailRead(mid);
                }
            } catch (e) {}
            _tmp_dl.each(function(item){
				try {
					var e = Element.getParentNodeByClassName(EL, item.name);
					if (e) {
						try {
							item.exec(e, event);
						} catch (e) {}
						Event.stop(event);
						return false;
					}
				} catch(e) {}
            });
        });
        */
		
		var _tmp_dl_clk = [{
            name: 's_overview_c',
            exec: function(){
                var _t = setTimeout(function(){
                    clearTimeout(_t);
                    _t = null;
                    MLMD('conference');
                }, 100);
            }
        }, {
			name: 's_star',
			exec: function() {
				var e = arguments[0];
				var rid = e.rid ? e.rid : e.getAttribute('rid');
				var level = e.level ? e.level : e.getAttribute('level');
				self.setStar(e, rid, level);
			}
		}, {
			name: 's_sort_sender',
			exec: function() {
				for(var key in self._order) {
					if(key == 'star' || key == 'sender') continue;
					self._order[key] = 0;
				}
				if(self._order.sender == 0) {
					self._order.sender = 1;
				} else {
					self._order.sender = 0;
				}
				self._order_name = 'sender';
				self.getMailPage(self.currentFolder, self._currentPage, null, null, {
					sort: 'sender',
					order: self._order.sender
				});
			}
		}, {
			name: 's_sort_subject',
			exec: function() {
				for(var key in self._order) {
					if(key == 'star' || key == 'subject') continue;
					self._order[key] = 0;
				}
				if(self._order.subject == 0) {
					self._order.subject = 1;
				} else {
					self._order.subject = 0;
				}
				self._order_name = 'subject';
				self.getMailPage(self.currentFolder, self._currentPage, null, null, {
					sort: 'subject',
					order: self._order.subject
				});
			}
		}, {
			name: 's_sort_date',
			exec: function() {
				for(var key in self._order) {
					if(key == 'star' || key == 'date') continue;
					self._order[key] = 0;
				}
				if(self._order.date == 0) {
					self._order.date = 1;
				} else {
					self._order.date = 0;
				}
				self._order_name = 'date';
				self.getMailPage(self.currentFolder, self._currentPage, null, null, {
					sort: 'date',
					order: self._order.date
				});
			}
		}, {
			name: 's_sort_star',
			exec: function(EL, event) {
				var _level = (self._order.star + 1)%self.multiStar.star.length;
				self._order.star = _level;
				self.multiStar.star.each(function(item) {
					if(Element.hasClassName(EL, item)) Element.removeClassName(EL, item);
				});
				Element.addClassName(EL, 'icon_star' + _level);
				self.getMailPage(self.currentFolder, self._currentPage, null, null, {
					sort: 'star',
					order: self._order.star
				});
			}
		}, {
			name: 'selpage',
			exec: function(EL, event) {
				var mune_page = [], _a = [];
                for (var i = 0; i < self.pagecounttmp; i++) {
                    _a.push(i + 1);
                }
                _a.each(function(item){
                    mune_page.push({
                        text: item,
                        onclick: function(){
                            self.getMailPage(self.currentFolder, (item - 1));
                        }
                    })
                });
                menu.showMenu(EL.parentNode, DOM.sohuMailMain, mune_page, 'menu menu_sel', true, null, event);
			}
		}];
		
		var _gpcn = Element.getParentNodeByClassName, _gpatr = Element.getParentNodeByAttribute, _gptn = Element.getParentNodeByTagName;
		DOM.mailList.observe('click', function(event) {
			if(isConferenceMode) return false;
			var el = event.target, _tmp = _tmp_dl.concat(_tmp_dl_clk);
			_tmp.each(function(item) {
				var e = _gpcn(el, item.name);
				if(e) {
					Event.stop(event);
					item.exec(e, event);
				}
				return false;
			});
			
			var EL = el;
			try {
                var selallid = EL.id ? EL.id : EL.getAttribute('id');
                if (selallid == 'selectAllBoxID') 
                    self.selectAll(EL);
            } catch (e) {}
            try {
                var _value = EL.value;
                var _unread = EL.unread ? EL.unread : EL.getAttribute('unread');
                var _id = EL.id ? EL.id : EL.getAttribute('id');
                if (typeof _unread != 'undefined') {
                    if (_unread == '1' || _unread == 'true') 
                        _unread = true;
                    else 
                        _unread = false;
                }
                if (_value && (typeof _unread == 'boolean') && _id != 'selectAllBoxID') {
                    self.selectThis(EL, _value, _unread);
                }
            } catch (e) {}
			
		}).observe('mouseover', function(event) {
			if(isConferenceMode) return false;
			var el = event.target, e = _gpcn(el, 'bt-common');
			e && $(e).addClassName('bt-common-hover');
			(function() {
				/*
				var EL = event.target, etr = EL.parentNode.parentNode;
                var is_tr = etr.id ? etr.id : etr.getAttribute('id');
				if (EL.parentNode.tagName.toLowerCase() == 'td' && is_tr && is_tr.include('tr')) TableMouseOver(etr);
				*/
				var _e = _gptn(el, 'tr'), _eid = _e.getAttribute('id');
				if(_e && _eid && _eid.startsWith('tr')) TableMouseOver(_e);
				if ($(el).hasClassName('selpage')) $(el).addClassName('select-arrow-over');
			})();
		}).observe('mouseout', function(event) {
			if(isConferenceMode) return false;
			var el = event.target, e = _gpcn(el, 'bt-common');
			e && $(e).removeClassName('bt-common-hover');
			(function() {
				/*
				var EL = event.target, etr = EL.parentNode.parentNode;
                var is_tr = EL.parentNode.parentNode.id ? EL.parentNode.parentNode.id : EL.parentNode.parentNode.getAttribute('id');
				if (EL.parentNode.tagName.toLowerCase() == 'td' && is_tr && is_tr.include('tr')) TableMouseOut(etr);
				*/
				var _e = _gptn(el, 'tr'), _eid = _e.getAttribute('id');
				if(_e && _eid && _eid.startsWith('tr')) TableMouseOut(_e);
				if($(el).hasClassName('selpage')) $(el).removeClassName('select-arrow-over');
			})();
		}).observe('mousedown', function(event) {
			if(isConferenceMode) return false;
			var el = event.target, e = _gpcn(el, 'bt-common');
			e && $(e).addClassName('bt-common-press');
			if(!Event.isLeftClick(event)) return false;
			var mid = _gpatr(el, 'mid');
			if(mid) mailRead.getMailRead(mid.attribute);
			if($(el).hasClassName('selpage')) $(el).addClassName('select-arrow-press');
		}).observe('mouseup', function(event) {
			if(isConferenceMode) return false;
			var el = event.target, e = _gpcn(el, 'bt-common');
			e && $(e).removeClassName('bt-common-press');
			if($(el).hasClassName('selpage')) $(el).removeClassName('select-arrow-press');
		});
		
		/*
		Event.observe(DOM.mailList, 'click', function(event) {
			if (isConferenceMode) return false;
            var EL = event.target;
			try {
                var selallid = EL.id ? EL.id : EL.getAttribute('id');
                if (selallid == 'selectAllBoxID') 
                    self.selectAll(EL);
            } catch (e) {}
            try {
                var _value = EL.value;
                var _unread = EL.unread ? EL.unread : EL.getAttribute('unread');
                var _id = EL.id ? EL.id : EL.getAttribute('id');
                if (typeof _unread != 'undefined') {
                    if (_unread == '1' || _unread == 'true') 
                        _unread = true;
                    else 
                        _unread = false;
                }
                if (_value && (typeof _unread == 'boolean') && _id != 'selectAllBoxID') {
                    self.selectThis(EL, _value, _unread);
                }
            } catch (e) {}
			_tmp_dl.each(function(item){
				try {
					var e = Element.getParentNodeByClassName(EL, item.name);
					if (e) {
						Event.stop(event);
						return false;
					}
				} catch(e) {}
            });
			_tmp_dl_clk.each(function(item) {
				try {
					var e = Element.getParentNodeByClassName(EL, item.name);
					if (e) {
						item.exec(e, event);
						Event.stop(event);
						return false;
					}
				} catch(e) {}
			});
		});
		
        Event.observe(DOM.mailList, 'mouseover', function(event){
            if (isConferenceMode) 
                return false;
            var EL = event.target, etr = EL.parentNode.parentNode;
            try {
                var is_tr = etr.id ? etr.id : etr.getAttribute('id');
            } catch (e) {}
			try {
				if (EL.parentNode.tagName.toLowerCase() == 'td' && is_tr && is_tr.include('tr')) {
					TableMouseOver(etr);
				}
			} catch(e) {}
        });
        Event.observe(DOM.mailList, 'mouseout', function(event){
            if (isConferenceMode) 
                return false;
            var EL = event.target, etr = EL.parentNode.parentNode;
            try {
                var is_tr = EL.parentNode.parentNode.id ? EL.parentNode.parentNode.id : EL.parentNode.parentNode.getAttribute('id');
            } catch (e) {}
			try {
				if (EL.parentNode.tagName.toLowerCase() == 'td' && is_tr && is_tr.include('tr')) {
					TableMouseOut(etr);
				}
			} catch(e) {}
        });
        */
		
		// 文件夹管理的事件绑定
		var _tmp_mg_dl = [
			{name: 's_manage_folder', exec: function(EL, event) {
				var fid = EL.fid ? EL.fid : EL.getAttribute('fid');
                changePanel('mailList', fid);
			}},
			{name: 's_manage_filter', exec: function() {
				changePanel('mailConfiguration', 'mailCfgFilter');
			}},
			{name: 's_manage_create', exec: function() {
				self.createNewFolder();
			}},
			{name: 's_manage_cancel', exec: function() {
				self.clearNewFolderName();
				self.hideNewFolderArea();
			}},
			{name: 's_manage_show', exec: function() {
				self.showNewFolderArea();
			}},
			{name: 's_manage_clearfolder', exec: function(EL, event) {
				var fid = EL.fid ? EL.fid : EL.getAttribute('fid');
				self.clearFolder(fid);
			}},
			{name: 's_manage_pop', exec: function(EL, event) {
				mailPop.getPop3List();
			}},
			{name: 's_manage_change', exec: function(EL, event) {
				var fid = EL.fid ? EL.fid : EL.getAttribute('fid');
				self.changeUserFolder(fid);
			}},
			{name: 's_manage_delete', exec: function(EL, event) {
				var fid = EL.fid ? EL.fid : EL.getAttribute('fid');
				self.deleteUserFolder(fid);
			}}
		];
		
		/*
		Event.observe(DOM.newFolderList, 'mousedown', function(event) {
			var EL = $(event.target);
			try {
				_tmp_mg_dl.each(function(item) {
					var e = _gpcn(EL, item.name);
					if(e) {
						item.exec(EL, event);
					}
					if(e && e.nodeName.toLowerCase() == 'a') {
						Event.stop(event);
					}
					return false;
				});
			} catch(e) {}
			return false;
		});
		*/
		var _gpcn = Element.getParentNodeByClassName, _gpatr = Element.getParentNodeByAttribute;
		DOM.newFolderList.observe('click', function(event) {
			var el = event.target;
			_tmp_mg_dl.each(function(item) {
				var e = _gpcn(el, item.name);
				if(e) {
					item.exec(el, event);
				}
				if(e && e.nodeName.toLowerCase() == 'a') {
					Event.stop(event);
				}
				return false;
			});
		}).observe('mouseover', function(event) {
			var el = event.target, e = _gpcn(el, 'bt-common');
			e && $(e).addClassName('bt-common-hover');
		}).observe('mouseout', function(event) {
			var el = event.target, e = _gpcn(el, 'bt-common');
			e && $(e).removeClassName('bt-common-hover');
		}).observe('mousedown', function(event) {
			var el = event.target, e = _gpcn(el, 'bt-common');
			e && $(e).addClassName('bt-common-press');
		}).observe('mouseup', function(event) {
			var el = event.target, e = _gpcn(el, 'bt-common');
			e && $(e).removeClassName('bt-common-press');
		});
		
    },
    getFolderItem: function(id) {
        var folder_item = {};
        var _unread = 0;
        FolderList.each(function(item){
			/*
            if (item.folder_id != 2 && item.folder_id != 3 && item.folder_id != 4) 
                _unread += item.unread;
            */
            if (item.folder_id == id) 
                folder_item = item;
        });
		return folder_item;
		/*
        if (id == -2) {
            return {
                folder_id: -2,
                name: '未读邮件',
                size: 0,
                total: _unread,
                unread: _unread
            };
        } else {
            return folder_item;
        }
        */
    },
    getMailPage: function(folder, pageIndex, onSuccessCallback, callback){
        this.currentFolder = (folder == 0) ? 1 : folder;
        this._currentPage = pageIndex;
        if (!onSuccessCallback) {
            this.onSuccessCallback = onSuccessCallback = this.getMailPageCallback;
        } else {
			this.onSuccessCallback = onSuccessCallback;
		}
        if (callback && typeof callback == 'function') {
            this.mailCallbackFunc = callback;
        }
        var startIndex = this._currentPage * PAGE_CAPACITY;
        if (isNaN(startIndex) || startIndex < 0) {
            startIndex = 0;
        }
        if (isNaN(PAGE_CAPACITY) || PAGE_CAPACITY < 0) {
            PAGE_CAPACITY = 20;
        }
        if (typeof this.starLevel == 'undefined') {
            this.starLevel = 0;
        }
        var params = {
            folder_id: this.currentFolder,
            start: startIndex,
            length: PAGE_CAPACITY
        };
		var _sort = arguments[4];
		if(_sort && typeof _sort == 'object') {
			try {
				if(this._sort.sort != _sort.sort || this._sort.order != _sort.order) {
					this._sort = _sort;
					this.mailListCache['inbox' + this.currentFolder] = [];
					this.refreshListFlag = true;
				}
			} catch(e) {}
		}
		try {
			Object.extend(params, this._sort);
		} catch(e) {}
        var _list = this.mailListCache['inbox' + this.currentFolder] ? this.mailListCache['inbox' + this.currentFolder][this._currentPage] : false;
        if (Object.isArray(_list) && _list.length > 0) {
            this.onSuccessCallback(_list);
        } else {
            folder_list(params, this.onSuccessCallback.bind(this));
        }
    },
    getMailPageCallback: function(ret) {
                try{
                    if(ret.status == false){
                        mailfolder.check_callback = function(){ML();};
                        mailfolder.valid_success(ret);
                        return;
                    }
                }catch(e)
                {}
		try {
			this._currentPage = this._currentPage < 0 ? 0 : this._currentPage;
			if (this.mailListCache['inbox' + this.currentFolder]) {
				this.mailListCache['inbox' + this.currentFolder][this._currentPage] = ret;
			} else {
				this.refreshListFlag = true;
			}
			this.currentPage = this._currentPage;
			// 为代码整理的测试
			mailRead.cacheList = ret;
			mailRead._prev_page = (this.currentPage <= 0) ? null : this.currentPage - 1, mailRead._next_page = this.currentPage + 1;
			mailRead.folder = this.currentFolder;
			mailRead.page = this.currentPage;
		} catch(e) {}
		
		try {
			if (typeof ret == 'object') {
				this.currentTotalCount = Math.abs(ret[0] && ret[0]['total_count'] ? ret[0]['total_count'] : this.getFolderItem(this.currentFolder).total);
				// this.currentTotalCount = typeof this.currentTotalCount == 'number' ? Math.abs(this.currentTotalCount) : 0;
				_currentPageFolderList = ret;
			}
		} catch(e) { }
        try {
            hiddenAllPanel();
            this.refreshDisplayBlock(ret);
            this.refreshFolderListNewMail();
            try {
                DOM.sohuMailMain.scrollTop = this.listScrollPos;
            } catch (e) {}
            try {
				var self = this;
                this.list_scroll_pos_timer = setInterval(function(){
                    self.listScrollPos = DOM.sohuMailMain.scrollTop;
                }, 100);
            } catch (e) {}
        } catch (e) {}
        this.currentFolderCache = this.currentFolder;
        this.currentPageCache = this.currentPage;
		this.currentCountCache = PAGE_CAPACITY;
        deleteLoadPage();
        
        // 如果有callback
        try {
            if (this.mailCallbackFunc) {
				this.mailCallbackFunc();
				this.mailCallbackFunc = null;
			}
        } catch (e) {}
        try {
            mailPop.setPopMailListTag(ret);
        } catch (e) {}
		// 多彩星标的闪烁
		try {
			this.stopStar();
			this.runStar(ret);
		} catch(e) {}
        // load next page
        // 目前只对系统文件夹的数据进行缓存
        if (this.currentFolder == 1 || this.currentFolder == 5) {
            this.preLoadedMailList(this.currentPage + 1);
        }
		try {
			deleteLoadPage();
		} catch(e) {}
		try {
			var _tv = this.getFolderNamebyID(this.currentFolder);
            var titleValue = _tv.strip() == '' ? '无标题' : _tv;
            if (this.currentPage == 0) {
                addAjaxHistory('mailList_' + this.currentFolder, 'changePanel("mailList",' + this.currentFolder + ', true)', titleValue, this._is_rsh);
            } else {
                addAjaxHistory('mailList_' + this.currentFolder + '_' + this.currentPage, 'mailList._is_rsh=true;mailList.getMailPage(' + this.currentFolder + ', ' + this.currentPage + ');', titleValue, this._is_rsh);
            }
            this._is_rsh = false;
		} catch(e) {}
    },
	// 注销列表页面滚动的位置监听
    stopListScrollPos: function(){
        if (this.list_scroll_pos_timer) {
            clearInterval(this.list_scroll_pos_timer);
            this.list_scroll_pos_timer = null;
        }
    },

	// (UI部分)
    refreshDisplayBlock: function(ret){
        if (DOM.mailList.firstChild && DOM.mailList.firstChild.nodeType == 1 && this.currentFolder != -2 && (this.currentFolder == this.currentFolderCache) && (this.currentPage == this.currentPageCache) && (this.currentCountCache == PAGE_CAPACITY) && !this.refreshListFlag) {
            DOM.mailList.show();
            return false;
        }
        this.refreshListFlag = false;
		
		var ad_ct = function() {
			try {
				if(_is_xj || USE_SYS.name != 'sohu' || !sohuMailAds) return {t:'',b:''};
			} catch(e) {
				return {t:'',b:''};
			}
			var _ad1 = sohuMailAds.top.ads1.content[0],
				_ad2 = sohuMailAds.top.ads2.content[0],
				_ad3 = sohuMailAds.top.ads3.content[0],
				_bad = sohuMailAds.bottom.ads.content[0];
			var _top_ad = '<tr style="background:#FFFBDE;">'
				+'<td colspan="9" style="width:100%;">'
				+'<div class="f-lf" style="text-align:center;width:33%;"><a href="' + _ad1.href + '" target="_blank" hidefocus="true">' + _ad1.text + '</a></div>'
				+'<div class="f-lf" style="text-align:center;width:33%;"><a href="' + _ad2.href + '" target="_blank" hidefocus="true">' + _ad2.text + '</a></div>'
				+'<div class="f-lf" style="text-align:center;width:33%;"><a href="' + _ad3.href + '" target="_blank" hidefocus="true">' + _ad3.text + '</a></div>'
				+'</td>'
				+'</tr>',
				_bottom_ad = '<tr style="background:#FFFBDE;">'
				+'<td colspan="9" style="text-align:center;border-bottom:none;">'
				+'<a href="' + _bad.href + '" target="_blank" hidefocus="true">' + _bad.text + '</a>'
				+'</td>'
				+'</tr>';
			return {t:_top_ad, b:_bottom_ad};
		}, _ad = ad_ct();
		
        var table = this.createTable(ret, [_ad.t, _ad.b]);
		
		var _op = [], mc = mailConference, _f = this.currentFolder;
		this.pagecounttmp = parseInt(this.currentTotalCount % PAGE_CAPACITY) > 0 ? parseInt(this.currentTotalCount / PAGE_CAPACITY) + 1 : parseInt(this.currentTotalCount / PAGE_CAPACITY);
		_op.push('<div class="l-area">');
		_op.push(mc.createDeleteEL(true));
		if (_f != 2 && _f != 3 && _f != 4) _op.push(mc.createDelEL());
		if (_f == 4) _op.push(mc.createUnDelEL());
		if (_f == 5) _op.push(mc.createUnspamEL());
		else if(_f != 2 && _f != 3) _op.push(mc.createSpamEL());
		_op.push(mc.createSprEL());
		if (_f != 2 && _f != 3 && _f != 4 && _f > -5) _op.push(mc.createMkEL());
		if(_f != 2 && _f != 3) _op.push(mc.createMoveEL());
		_op.push('</div>');
		_op.push('<div class="r-area">');
		if(this.pagecounttmp == 0 || ((this.currentPage+1) == 1 && (this.currentPage+1) == this.pagecounttmp)) {
			_op.push(mc.createFirstPageEL(true));
			_op.push(mc.createPrevPageEL(true));
			_op.push(mc.createNextPageEL(true));
			_op.push(mc.createEndPageEL(true));
		} else if((this.currentPage+1) == 1) {
			_op.push(mc.createFirstPageEL(true));
			_op.push(mc.createPrevPageEL(true));
			_op.push(mc.createNextPageEL());
			_op.push(mc.createEndPageEL());
		} else if((this.currentPage+1) == this.pagecounttmp) {
			_op.push(mc.createFirstPageEL());
			_op.push(mc.createPrevPageEL());
			_op.push(mc.createNextPageEL(true));
			_op.push(mc.createEndPageEL(true));
		} else {
			_op.push(mc.createFirstPageEL());
			_op.push(mc.createPrevPageEL());
			_op.push(mc.createNextPageEL());
			_op.push(mc.createEndPageEL());
		}
		_op.push(mc.createSelPageEL(this.currentPage+1));
		_op.push('</div>');
		var _opht = _op.join('');
		
        var mailcontent = ['<div class="operate">', _opht, '</div>', '<div class="m-content">', table, '</div>', '<div class="operate2">', _opht, '</div>'].join('');
        DOM.mailList.innerHTML = mailcontent;
        DOM.mailList.show();
		
		
		
        try {
			/*
            this.pagecounttmp = parseInt(this.currentTotalCount % PAGE_CAPACITY) > 0 ? parseInt(this.currentTotalCount / PAGE_CAPACITY) + 1 : parseInt(this.currentTotalCount / PAGE_CAPACITY);
            // 重用会话界面的代码
            var top_bar = null, bottom_bar = null;
            $A(DOM.mailList.childNodes).each(function(item){
                if (item.className == 'operate') 
                    top_bar = item;
                if (item.className == 'operate2') 
                    bottom_bar = item;
            });
			var top_bar_r = top_bar.firstChild, bottom_bar_r = bottom_bar.firstChild;
            var mc = mailConference;
            var delete_el_t = mc.createDeleteEL(), del_el_t = mc.createDelEL(), move_el_t = mc.createMoveEL(), spam_el_t = mc.createSpamEL();
            var delete_el_b = delete_el_t.cloneNode(true), del_el_b = del_el_t.cloneNode(true), move_el_b = move_el_t.cloneNode(true), spam_el_b = spam_el_t.cloneNode(true);
            var sprt_t = mc.createSprEL(), sprt_b = sprt_t.cloneNode(true);
			
            top_bar.appendChild(delete_el_t);
            bottom_bar.appendChild(delete_el_b);
			
			$([delete_el_t, delete_el_b]).each(function(item) {
				$(item.firstChild).addClassName('bt-first');
			});
            
            if (this.currentFolder != 2 && this.currentFolder != 3 && this.currentFolder != 4) {
                top_bar.appendChild(del_el_t);
                bottom_bar.appendChild(del_el_b);
            }
            
            if (this.currentFolder == 4) {
                var undelt_el_t = mc.createUnDelEL(), undelt_el_b = undelt_el_t.cloneNode(true);
                top_bar.appendChild(undelt_el_t);
                bottom_bar.appendChild(undelt_el_b);
            }
            
            if (this.currentFolder == 5) {
                var umspam_el_t = mc.createUnspamEL(), umspam_el_b = umspam_el_t.cloneNode(true);
                top_bar.appendChild(umspam_el_t);
                bottom_bar.appendChild(umspam_el_b);
            } else {
                if (this.currentFolder != 2 && this.currentFolder != 3) {
                    top_bar.appendChild(spam_el_t);
                    bottom_bar.appendChild(spam_el_b);
                }
            }
			
			top_bar.appendChild(sprt_t);
			bottom_bar.appendChild(sprt_b);
            
            if (this.currentFolder != 2 && this.currentFolder != 3 && this.currentFolder != 4) {
                var mark_el_t = mc.createMkEL(), mark_el_b = mark_el_t.cloneNode(true);
                top_bar.appendChild(mark_el_t);
                bottom_bar.appendChild(mark_el_b);
            }
			if (this.currentFolder != 2 && this.currentFolder != 3) {
                top_bar.appendChild(move_el_t);
                bottom_bar.appendChild(move_el_b);
            }
            
            if ((this.currentFolder == 4 || this.currentFolder == 5) && ret.length > 0) {
				
				top_bar.appendChild(sprt_t.cloneNode(true));
				bottom_bar.appendChild(sprt_b.cloneNode(true));
				
                var clear_el_t = mc.createClearEL(), clear_el_b = clear_el_t.cloneNode(true);
                top_bar.appendChild(clear_el_t);
                bottom_bar.appendChild(clear_el_b);
            }

			//添加自定义按钮 add by zhangyinghui
			var btnList=ExecFunc("createBtnInMailList");
			if(btnList && (btnList instanceof Array)){
				var n = btnList.length;
				for (var i=0;i<n ;i++ ){
					if(btnList[i])
						top_bar.appendChild(btnList[i]);
				}
			}
            
            var f_p_t = mc.createFirstPageEL(), p_p_t = mc.createPrevPageEL(), n_p_t = mc.createNextPageEL(), e_p_t = mc.createEndPageEL(), s_p_t = mc.createSelPageEL(this.currentPage + 1);
            var f_p_b = f_p_t.cloneNode(true), p_p_b = p_p_t.cloneNode(true), n_p_b = n_p_t.cloneNode(true), e_p_b = e_p_t.cloneNode(true), s_p_b = s_p_t.cloneNode(true);
            
			top_bar_r.appendChild(f_p_t);
			bottom_bar_r.appendChild(f_p_b);
			
			top_bar_r.appendChild(p_p_t);
			bottom_bar_r.appendChild(p_p_b);
			
			top_bar_r.appendChild(n_p_t);
			bottom_bar_r.appendChild(n_p_b);
			
			top_bar_r.appendChild(e_p_t);
			bottom_bar_r.appendChild(e_p_b);
			
			top_bar_r.appendChild(s_p_t);
			bottom_bar_r.appendChild(s_p_b);
			
			if((this.currentPage + 1) == 1) {
				$([f_p_t,f_p_b,p_p_t,p_p_b]).each(function(item) {
					// $(item).addClassName('lk-disable');
					item.className = 'lk-enable lk-disable';
				});
			} else if((this.currentPage + 1) == this.pagecounttmp) {
				$([n_p_t,n_p_b,e_p_t,e_p_b]).each(function(item) {
					// $(item).addClassName('lk-disable');
					item.className = 'lk-enable lk-disable';
				});
			}
			*/
        } catch (e) {}
		
		// 邮件操作提示信息
		try {
			this.createMessageInfo();
		} catch(e) {}
        
        try {
			/*
            Element.insert(DOM.mailList, {
                bottom: panel_str
            });
            */
            // 如果是在 草稿箱 或者 已发送 里面 标题换成 收件人
			/*
            if (this.currentFolder == 2 || this.currentFolder == 3) {
                try {
                    // $('send_reciver').innerHTML = '收件人';
                } catch (e) { }
            }
            // 邮件列表的操作提示信息设置显示5秒
            var msgDiv = $('messageDiv');
            if (msgDiv) {
                setTimeout(function(){
                    try {
                        msgDiv.hide();
                    } 
                    catch (e) { }
                }, 5000);
            }
            */
        } catch (e) {}
        
        // 霸王邮广告的显示
		/*
        try {
            (function(){
                var ad1 = $('top_ad_1'), ad2 = $('top_ad_2'), ad3 = $('top_ad_3'), ad4 = $('bottom_ad'), mlt = $('mail_list_top'), mlb = $('mail_list_bottom'), ad_str = function(item){
                    return '<a href="' + item.href + '" target="_blank" hidefocus="true">' + item.text + '</a>';
                };
                USE_SYS.name == 'sohu' && sohuMailAds && (typeof sohuMailAds == 'object') && ad1 && ad2 && ad3 && ad4 &&
                (function(){
					if(!sohuMailAds.top.show || !sohuMailAds.bottom.show) return false;
                    ad1.innerHTML = ad_str(sohuMailAds.top.ads1.content[0]);
                    ad2.innerHTML = ad_str(sohuMailAds.top.ads2.content[0]);
                    ad3.innerHTML = ad_str(sohuMailAds.top.ads3.content[0]);
                    ad4.innerHTML = ad_str(sohuMailAds.bottom.ads.content[0]);
					mlt.show();
					mlb.show();
                })();
            })();
        } catch (e) {}
        */
    },
	
	// 多彩星标的滚动
	runStar: function(ret) {
		try {
			if(PROFILE.usestar) return false;
		} catch(e) {}
		if(ret.length == 0) return false;
		var _flag = false;
		ret.each(function(item) {
			if(!_flag && item.star != 0) _flag = true;
		});
		if(_flag) return false;
		var _id = this.multiStar.id = ret[0].rowid, _el = $('tr_' + ret[0].rowid), _s = _el && _el.getElementsByTagName('td'),
		_img = this.multiStar.imgel = _s[4].firstChild, _sub = this.multiStar.subel = _s[5].firstChild, _index = 0;
		if(!_img || !_sub) return false;
		var self = this;
		this.multiStar.timer = setInterval(function() {
			try {
				if(!self.multiStar.star[_index]) {
					self.stopStar();
					_index = 0;
					try {
						arguments.callee();
					} catch(e) {}
					return false;
				}
				self.setStarClass(_img, self.multiStar.star[_index]);
				// _img.src = MailConst.ALL + self.multiStar.img[_index];
				_img.title = self.multiStar.title[_index];
				_sub.style.color = self.multiStar.color[_index];
				_index ++;
			} catch(e) {}
		}, 2000);
	},
	stopStar: function() {
		if(this.multiStar.timer) {
			clearInterval(this.multiStar.timer);
			this.multiStar.timer = null;
		}
	},
	setStarClass: function(el, classname) {
		this.multiStar.star.each(function(item) {
			try {
				Element.removeClassName(el, item);
			} catch(e) {}
		});
		Element.addClassName(el, classname);
	},
	
    createSubHead: function(){
        var scount = (this.currentPage * PAGE_CAPACITY) + 1;
        var ecount = ((this.currentPage + 1) * PAGE_CAPACITY) < this.currentTotalCount ? ((this.currentPage + 1) * PAGE_CAPACITY) : this.currentTotalCount;
        var cmcount = [scount, '-', ecount].join('');
        var mailnum = this.currentTotalCount > 0 ? ['第 <font id="spMailRange">', cmcount, '</font> 封，共 <font id="spMailCount">', this.currentTotalCount, '</font> 封邮件'].join('') : '共 <font id="spMailCount"> 0 </font> 封邮件';
        return '<tr class="top_tr bb"><td>&nbsp;</td><td><input id="selectAllBoxID" type="checkbox" /></td><td colspan=3> 全选 / 取消全选 </td><td colspan=4><div style="float:right;text-align:right;"><span style="margin-right:16px;_margin-right:32px;">' + mailnum + '</span></div></td></tr>';
    },
	
    createMessageInfo: function(){
		if(!messageInfo || messageInfo == '') return false;
		Tips.show(messageInfo, 5);
		messageInfo = '';
		/*
        var res = '';
        var t = new Template(hintTemplate);
        if (messageInfo != '') {
            var data = {};
            data['message'] = messageInfo;
            res = t.evaluate(data);
        }
        messageInfo = '';
        return res;
        */
    },

	// (UI部分)
    selectAll: function(checkAllElement) {
        var _sa = $A($('inbox').getElementsBySelector('input')), _sal = _sa.slice(1);
        if (checkAllElement.checked) {
            _currentPageFolderList.each(function(mailItem, index){
                mailItem.checked = true;
                // _sal[index].parentNode.parentNode.style.backgroundColor = '#FFCB7B';
				$(_sal[index].parentNode.parentNode).addClassName('item_focus');
                _sal[index].checked = true;
            });
            
        } else {
            _currentPageFolderList.each(function(mailItem, index){
                mailItem.checked = false;
                // _sal[index].parentNode.parentNode.style.backgroundColor = '';
				$(_sal[index].parentNode.parentNode).removeClassName('item_focus');
                _sal[index].checked = false;
            });
        }
    },

    selectThis: function(checkboxElement, id, is_unead){
        if (checkboxElement.checked) {
            // $('tr_' + id).style.backgroundColor = '#FFCB7B';
			$('tr_' + id).addClassName('item_focus');
            _currentPageFolderList.find(function(mailItem){
                if (mailItem.rowid == id) {
                    mailItem.checked = true;
                    if (is_unead) {
                        mailItem.unread = true;
                    }
                }
            });
        } else {
            // $('tr_' + id).style.backgroundColor = '';
			$('tr_' + id).removeClassName('item_focus');
            _currentPageFolderList.find(function(mailItem){
                if (mailItem.rowid == id) {
                    mailItem.checked = false;
                    if (is_unead) {
                        mailItem.unread = false;
                    }
                }
            });
			try {
				$('selectAllBoxID').checked = false;
			} catch(e) {}
        }
    },
	
	
	
	// 删除邮件 -> 将邮件移动到回收站中
    deleteMailItems: function(){
        var _mails = this.getSelectMailList().selected;
        if (_mails == '' || _mails == null) {
            _dialog.alert({
                info: '请选择您要操作的邮件'
            });
            return;
        }
        messageInfo = '邮件已删除！';
        var _sel_obj = this.getSelectMailList().obj;
		try {
			var sys_mails = this.returnDelZhiYou(_sel_obj);
		} catch(e) {
			var sys_mails = '';
		}
        if (this.currentFolder == 4) {
            var params = {
                // 如果从回收站中的邮件删除，就直接清除掉
                src: this.currentFolder,
                dest: -1,
                id: _mails,
                method: 1,
                sys_mails: sys_mails
            }
        } else {
            var params = {
                // 邮件转移到回收站
                src: this.currentFolder,
                dest: 4,
                id: _mails,
                method: 1,
                sys_mails: sys_mails
            }
        }
        mail_move(params, this.moveMailToCallBack.bind(this, params));
    },

	// 反删除（只在已删除中出现）
    unDeleteMailItems: function() {
        var _mails = this.getSelectMailList().selected;
        if (_mails == '' || _mails == null) {
            _dialog.alert({
                info: '请选择您要操作的邮件'
            });
            return;
        }
        messageInfo = '邮件已恢复！';
        var params = {
            // 如果从回收站中的邮件删除，就直接清除掉
            id: _mails,
            method: 4
        }
        mail_move(params, this.moveMailToCallBack.bind(this, params));
    },

	// 判断被删除的邮件是否为直邮邮件
    returnDelZhiYou: function(obj_list) {
        var sohu_zhiyou = [];
        if (obj_list.length > 0) {
			try {
				obj_list.each(function(item) {
					if(item.envelope.from.length == 0) return false;
					var _addr = item.envelope.from[0][1];
					
					if(getZhiYouAccount(_addr)) {
						var _read = item.have_read ? 1 : 0;
						sohu_zhiyou.push([_addr, '|', _read].join(''));
					}
				});
				if (sohu_zhiyou.length > 0) 
					return sohu_zhiyou.join(',');
			} catch(e) {}
        }
        return '';
    },

	// 永久删除邮件 -> 将邮件移动到-1中
    permanentDeleteMailItems: function(){
        var _mails = this.getSelectMailList().selected;
        if (_mails == '' || _mails == null) {
            _dialog.alert({
                info: '请选择您要操作的邮件'
            });
            return;
        }
        messageInfo = '邮件已经永久删除！';
        var _sel_obj = this.getSelectMailList().obj;
		try {
			var sys_mails = this.returnDelZhiYou(_sel_obj);
		} catch(e) {
			var sys_mails = '';
		}
		var self = this;
        var confunc = function(){
            var params = {
                // 邮件转移到垃圾邮件箱中
                src: self.currentFolder,
                dest: -1,
                id: _mails,
                method: 1,
                sys_mails: sys_mails
            };
            mail_move(params, self.moveMailToCallBack.bind(self, params));
        };
        _dialog.confirm({
            info: '您真的确定要删除邮件？',
            click: function(){
                confunc();
            }
        });
        return;
        confunc();
    },

    spamMailItems: function() {
        var _mails = this.getSelectMailList().selected;
        if (_mails == '' || _mails == null) {
            _dialog.alert({
                info: '请选择您要操作的邮件'
            });
            return;
        }
		var _sel_obj = this.getSelectMailList().obj;
		try {
			var sys_mails = this.returnDelZhiYou(_sel_obj);
		} catch(e) {
			var sys_mails = '';
		}
		var _senders = [], _is_sys = false;
		_currentPageFolderList.each(function(item) {
			try {
				if (!_mails.include(item.rowid)) return false;
				var _e = [].concat(item.envelope.from).concat(item.envelope.from_after_1st_unread);
				if (!_is_sys && getSysAccount(_e[0][1])) _is_sys = true;
				if (!_senders.include(_e[1])) _senders.push(_e[0][1]);
			} catch(e) {}
		});
		
		/*
		messageInfo = '举报成功！邮件已清除！';
		var params = {
           	src: self.currentFolder,
           	dest: -1,
           	method: 3,
           	id: _mails,
			sys_mails: sys_mails
        };
        mail_move(params, this.moveMailToCallBack.bind(this, params));
        */
		var self = this;
		if(!mailConference.spamMailLayer(_senders, _is_sys, function() {
			// messageInfo = '举报成功！邮件已清除！';
			messageInfo = '';
			var params = {
            	src: self.currentFolder,
            	dest: -1,
            	method: 3,
            	id: _mails,
				sys_mails: sys_mails
        	};
        	// mail_move(params, self.moveMailToCallBack.bind(self, params));
			mail_move(params, function(ret) {
				self.moveMailToCallBack(params, ret);
				var _cid = $('content_id');
				if(_cid) {
					_cid.innerHTML = '<dt class="t-txt">举报成功！邮件已提交反垃圾系统数据中心！</dt><div><div> 今天搜狐反垃圾系统共收到<b> '+ ret.spamall +' </b>次举报 </div><div> 共拦截了<b> '+ ret.spammail +' </b>封垃圾邮件 </div><div> 感谢您对搜狐邮箱反垃圾工作的支持！ </div></div><div style="margin-top:20px;text-align:center;"><input class="button6" type="button" value="　关闭窗口　" onclick="_dialog.closeCustom();" /></div>';
				}
			});
		})) return false;
    },

	// 同时移动多封邮件，合并到moveMail函数中
    moveMailTo: function(folderTo){
        var _mails = this.getSelectMailList().selected;
        if (_mails == '' || _mails == null) {
            _dialog.alert({
                info: '请选择您要操作的邮件'
            });
            return;
        }
        messageInfo = '移动邮件成功！';
        var params = {
            src: this.currentFolder,
            dest: folderTo,
            method: 1,
            id: _mails
        };
        mail_move(params, this.moveMailToCallBack.bind(this, params));
    },

    moveMailToCallBack: function(params, ret){
    	// 清除邮件列表缓存
		this.clearListCache();
        this.refreshListFlag = true;
        var _p = 0, self = this;
        var _d = (params.dest > 0 && params.dest != 2 && params.dest != 3 && params.dest != 4) ? params.dest : (function(){
            _p = self.currentPage;
            return self.currentFolder;
        })();
        this.getMailPage(_d, _p, function(_ret){
            this.getMailPageCallback(_ret);
            folder_detail({}, this._getMailCountCallBack.bind(this));
        }.bind(this));
		try {
			var _l = Object.isArray(params.id) ? params.id.length : 1;
			FolderList.each(function(item) {
				if(item.folder_id == self.currentFolder) {
					item.total += _l;
				}
			});
		} catch(e) {}
    },
	
	// 获取被选中的list列表
    getSelectMailList: function() {
        var c = [];
        var u = [];
		$A($('inbox').getElementsByTagName('input')).each(function(item, index) {
			if(index == 0) return false;
			if(item.checked) c.push(item.value);
		});
        _currentPageFolderList.each(function(mailItem){
            if (c.include(mailItem.rowid)) {
                u.push(mailItem);
            }
        });
        return {
            selected: c,
            obj: u
        };
    },

	// (UI部分)
    createTable: function(ret) {
        var tableHTML = [];
		var data = {};
		data['star_level'] = 'icon_star' + this._order.star;
		var _sty = this._order[this._order_name] == 1 ? 'order-top' : 'order-bottom';
		data['sort_' + this._order_name] = '<span class="am '+ _sty +'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>';
        var lists = [], liste = [];
		lists.push('<tr id="mail_list_top" class="m-list-ad" style="display:none;">');
        lists.push(['<td colspan="9" style="width:100%;"><div id="top_ad_1" style="float:left;text-align:center;width:33%;"></div><div id="top_ad_2" style="float:left;text-align:center;width:33%;"></div><div id="top_ad_3" style="width:33%;text-align:center;float:left;"></div></td>'].join(''));
        lists.push('</tr>');
		tableHTML.push('<table border="0" cellpadding="0" cellspacing="0" id="inbox" class="inbox">');
        tableHTML.push(mailTitleTemplate);
        tableHTML.push(this.createSubHead());
		tableHTML.push(new Template(mailTitle1).evaluate(data));
        // tableHTML.push(lists.join(''));
		if(arguments[1] && arguments[1][0]) tableHTML.push(arguments[1][0]);
		tableHTML.push(this.createMailList(0, ret));
        liste.push('<tr id="mail_list_bottom" class="m-list-ad" style="display:none;">');
        liste.push(['<td colspan="9" id="bottom_ad" style="text-align:center;border-bottom:none;"></td>'].join(''));
        liste.push('</tr>');
        // tableHTML.push(liste.join(''));
		if(arguments[1] && arguments[1][1]) tableHTML.push(arguments[1][1]);
        tableHTML.push('</table>');
        var x = tableHTML.join('');
        return x;
    },

	// 邮件列表部分
    createMailList: function(f, ret){
        if (ret.length == 0) {
            return '<tr><td colspan="9"><div class="m-no-list"> 当前邮件夹没有邮件 </div></td><td></td></tr>';
        }
        var tmpString = [];
        var x, mtime;
        var imgID, msgName, folder, isReadClass, attachmentIcon, date, email, folderIcon, sender, size, subject, xname, xaddr, xsubject;
        var now = new Date();
        // var y = now.toString().split(' ');
        var cyear = now.getFullYear();
        var cmonth = now.getMonth() + 1;
        var cday = now.getDate();
        var showSenderAddr = mailCfgClass.getProfileContent().showsenderaddr;
        var _len_ = ret.length;
        for (var i = f; i < _len_; i++) {
            x = ret[i];
            imgID = i;
            folder = this.currentFolder;
            if (x.have_read) {
                isReadClass = '';
            }
            else {
                isReadClass = 'noread';
            }
			
            var _tmpFolderIcon = 'icon_open';
            if (x.have_reply) {
                _tmpFolderIcon = 'icon_reply';
            }
            if (x.have_forward) {
                _tmpFolderIcon = 'icon_forward';
            }
            email = x.envelope.from &&
            x.envelope.from.length > 0 ? x.envelope.from[0] : ['', '未知邮件地址'];
            if (this.currentFolder == 2 || this.currentFolder == 3) {
                email = x.envelope.to &&
                x.envelope.to.length > 0 ? x.envelope.to[0] : ['', '未知邮件地址'];
            }
            if (!email) email = ['', '未知邮件地址'];
            folderIcon = (x.have_read ? _tmpFolderIcon : 'icon_close');
			var _is_sys_account = getSysAccount(email[1]);
			if (_is_sys_account) {
				folderIcon = _is_sys_account.icon;
				email = ['', _is_sys_account.name];
			}
			starIcon = '<span class="am s_star '+ this.multiStar.star[x.star] +'" rid="'+ x.rowid +'" level="'+ x.star +'" title="'+ this.multiStar.title[x.star] +'"></span>';
            try {
                var in_addr = mailAddressClass.addressHash.contact.email[email[1]];
            } catch (e) {}
            folderIcon = 'am ' + folderIcon;
            var sfrom = formatSysAccount(email);
			xname = (sfrom[0] && sfrom[0] != '') ? sfrom[0] : (in_addr && in_addr != '') ? in_addr : sfrom[0];
			xaddr = sfrom[1];
			sender = getSenderName([xname, xaddr], showSenderAddr);
			xsubject = x.envelope.subject;
            // mod by alva
            if (this.currentFolder == -2 || this.currentFolder <= -5) {
                subject = ['[', this.getFolderNamebyID(x.folder), '] ', xsubject].join('');
                if (x.folder == 2 || x.folder == 3) continue;
            } else {
                subject = ((xsubject.strip() == "") ? "无标题" : xsubject);
            }
			subject = subject.stripTags();
            date = x.envelope.display_date;
            size = strfsize(x.size);
			attachmentIcon = x.atts.length > 0 ? '<span class="am upload-fileicon"></span>' : '';
            var _tmpString = ['<tr id="tr_', x.rowid, '" class="', isReadClass, '">'+
							'<td width="1%"></td>'+
							'<td><input name="" type="checkbox" value="', x.rowid, '" unread="', ret[i].have_read, '"></td>'+
							'<td><img class="', folderIcon, '" src="', MailConst.ALL, '/spacer.gif', '" /></td>'+
							'<td><div style="margin-left:4px;">', attachmentIcon, '</div></td>'+
							'<td><div title="', xaddr, '">', sender, '</div></td>'+
							'<td style="cursor:pointer;">', starIcon, '</td>'+
							'<td style="cursor:pointer;"><div style="margin-left:8px;color:', (x.star > 0 ? this.multiStar.color[x.star] : (!x.have_read && _is_sys_account) ? _is_sys_account.color : ''), ';" mid="', x.rowid, '">', subject, '</div></td>'+
							'<td><div class="date-fmt">', date[0], '</div></td>', '<td><div class="date-fmt"><span>', size, '</span></div></td>'+
							'</tr>'].join('');
            tmpString.push(_tmpString);
        }
        return tmpString.join("");
    },
	
	// 获取邮件夹列表、每个邮件夹中邮件的总量、未读邮件数量 //
    getMailCount: function(init, callback){
        if (init && FOLDER && FOLDER != null) {
            this._getMailCountCallBack(FOLDER.evalJSON());
        } else {
            if (typeof(callback) == 'function') {
                folder_detail({}, function(ret){
                    this._getMailCountCallBack(ret);
                    callback();
                }.bind(this));
            } else {
                folder_detail({}, this._getMailCountCallBack.bind(this));
            }
        }
    },

	// 用户自建邮件夹ID: > 16
    _getMailCountCallBack: function(cont){
        // 用户自定义文件夹
        try {
            this.userFolderDetail(cont);
        } catch (e) {}
        FoldersData = cont;
        FolderList = cont.folders;
        try {
            if (mailConference) 
                mailConference.F = cont;
        } catch (e) {}
        FolderList.totalUnread = 0;
        this.totalUnread = 0;
		
		try {
			FolderList.each(function(item) {
				if(item.folder_id == -2) FolderList.totalUnread = this.totalUnread = item.unread;
			});
		} catch(e) {}
		
        try {
			/*
            FolderList.each(function(item){
                if (item.folder_id != 2 && item.folder_id != 3 && item.folder_id != 4) {
                    totalUnread += item.unread;
                }
            });
            */
        } catch (e) {}
        try {
            if (PROFILE && PROFILE.isconference) {
                mailConference.setConferenceNew(mailConference.F.folders);
            } else {
                this.refreshFolderListNewMail();
            }
        } catch (e) {}
    },

	// 刷新未读邮件数目
    refreshFolderListNewMail: function(){
        try {
            if (isConferenceMode && mailConference) {
                mailConference.setConferenceNew(mailConference.F.folders);
                return;
            }
        } 
        catch (e) {
        }
        // FolderList.totalUnread = 0;
		var _unread = 0;
        FolderList.each(function(item){
            // if (item.folder_id == 2 || item.folder_id == 3) return;
			
            var _d = $('spnewmail_' + item.folder_id);
            if (item.unread > 0) {
                if (_d) _d.innerHTML = '(' + item.unread + ')';
            } else {
                if (_d) _d.innerHTML = '';
            }
			
			if(item.folder_id == -2) {
				_unread = item.unread;
			}
        });
        // 由于未读邮件中没有作缓存，而其他的目录是作缓存的，所以会导致点击未读邮件可以获取最新数据，而点击收件箱的时候不会去更新，产生了数据不同步
        if ((TOTAL_UNREAD != _unread) && this.currentFolder == -2) {
        	this.clearListCache();
            this.refreshListFlag = true;
        }
        TOTAL_UNREAD = _unread;
        changeToolbarStyle('mailList', this.currentFolder);
    },
	
	// 读邮件时动态改变右侧邮件列表数目
    changeFolderListUnread: function(folder_id, is_unread) {
		var _i_unread = false;
		FolderList.each(function(item) {
			if(item.folder_id == folder_id && item.unread > 0 && is_unread) {
				item.unread--;
			}
			if(item.folder_id == -2 && !_i_unread) {
				item.unread--;
				_i_unread = true;
			}
		});
    },

	// 新邮件到来时动态改变右侧列表数目
    changeFolderListNewMailByFolderId: function(folder_id, syncnum){
        var flag = false;//FolderList中是否包含该folder
        for (var i = 0; i < FolderList.length; i++) {
            if (FolderList[i].folder_id == folder_id) {
                FolderList[i].total = FolderList[i].total + syncnum;
                FolderList[i].unread = FolderList[i].unread + syncnum;
                flag = true;
                break;
            }
        }
        FolderList.totalUnread += syncnum;
        if (!flag) {
            FolderList[FolderList.length] = {
                unread: syncnum,
                folder_id: folder_id,
                size: 0
            };
        }
    },
	
    deleteFolderFromFolderList: function(folder_id) {
        for (var i = 0; i < FolderList.length; i++) {
            if (FolderList[i].folder_id == folder_id) {
                FolderList.totalUnread -= FolderList[i].unread;
                FolderList = FolderList.slice(0, i).concat(FolderList.slice(i + 1));
                break;
            }
        }
    },

	// 是否显示所有的用户自建列表
    userFolderDetail: function(ret){
        var s = [];
        ret.folders.each(function(item){
            if (item.folder_id < 16 || IsEmail(item.name, false)) return false;
            s.push('<div id="folder_'+ item.folder_id +'" class="s_myfolder_' + item.folder_id + ' m-item"><a href="./main#mailList_' + item.folder_id + '" hidefocus="true">' + item.name + ' <b id="spnewmail_' + item.folder_id + '"></b></a></div>');
        });
        if (!DOM.newfolderArea) 
            DOM.newfolderArea = $('newfolderArea');
        DOM.newfolderArea.innerHTML = s.join('');
		DOM.newfolderArea.show();
    },

	// (UI部分)
    getFolderNamebyID: function(_id){
        try {
            if (_id == -2) return '未读邮件';
            var _name = '';
            FolderList.each(function(item){
                if (item.folder_id == _id) _name = item.name;
            });
            return _name;
        } catch (e) {}
    },
	
    changeUserFolder: function(_folder){
        this.renameFolderId = _folder;
        var fn = this.getFolderNamebyID(_folder);
        // $('nmf').show();
        $('newFolderName').value = fn;
        this.folderNameTobeChange = fn;
        this.isChangeFolderName = true;
    },

	// 更改邮件夹名称
    changeNewFolderName: function(_folder, newName){
		var self = this;
        var confunc = function(){
            var params = {
                folder_id: _folder,
                name: newName
            };
            folder_rename(params, self.createNewFolderCallBack.bind(self), self._changeFolderFailure.bind(self));
            self.isChangeFolderName = false;
            self.folderNameTobeChange = '';
        };
        _dialog.confirm({
            info: '你确定修改邮件夹的名称吗？',
            click: function(){
                confunc();
            }
        });
        return;
    },

	// 更改邮件夹名称失败函数
	_changeFolderFailure: function() {
		_dialog.alert({info: '更新邮件夹名称失败！'});
	},

	showNewFolderArea: function() {
		this.isChangeFolderName = false;
		$('newFolderName').value = '';
		// $('nmf').show();
	},

    hideNewFolderArea: function(){
        this.isChangeFolderName = false;
        $('newFolderName').value = '';
        // $('nmf').hide();
    },
	
	// 删除邮件夹中所有用户
    clearFolder: function(_folder_id){
		var self = this;
        var confunc = function(){
            var params = {
				src: _folder_id,
                dest: -1,
                method: 1,
				oclear: 1
            };
            mail_move(params, self._clearFolderCallBack.bind(self));
        };
        _dialog.confirm({
            info: '你确定删除邮件夹中的所有邮件吗？',
            click: function(){
                confunc();
            }
        });
        return;
    },

    _clearFolderCallBack: function(ret){
        // if (ret.is_success) {
            this.getMailCount(null, function(){
            	changePanel('newFolderList');
            });
        // }
    },

    deleteUserFolder: function(_folder){
        if (global_flag) return;
		var self = this;
        var confunc = function(){
            var params = {
                folder_id: _folder
            };
            folder_delete(params, self.deleteUserFolderCallBack.bind(self));
        };
        _dialog.confirm({
            info: '你确定删除邮件夹吗？',
            click: function(){
                confunc();
            }
        });
        return;
    },

	deleteUserFolderCallBack: function() {
		this.getMailCount(null, function() {
            mailfolder.initEvent();
			this.initFolderDetails();
		}.bind(this));
	},

	// 用户获得自建邮件夹属性的AJAX请求
	initFolderDetails: function(is_rsh, is_add) {
		folder_detail({}, this.initFolderDetailsCallBack.bind(this, is_rsh, is_add));
	},

	// initFolderDetails 函数的回调函数
    initFolderDetailsCallBack: function(is_rsh, is_add, ret) {
        hiddenAllPanel();
        // DOM.newFolderList.innerHTML = newFolderListTemplate;
        DOM.newFolderList.show();
        // var cont = ret;
		var _gm = G.isMobileUser(), tz = ret.totalSize, _use = (tz >= mailContentTotalSize) ? 
					'100%' : Math.round((tz/mailContentTotalSize)*1000)/10 + '%',
			_rate = _gm ? '2%' : _use,
			
			_total = strfsize(mailContentTotalSize), _remain = strfsize(ret.quotaSize - ret.totalSize),
			_status = _gm ? '无限容量' : '总容量 '+_total+'，可用 '+_remain;
		var _content = [], _content_pop = [];
		
		var _folder_item = function(obj) {
			return ['<tr class="',obj.cname,'"><td id="td_', obj.fid, '"><a hidefocus="true" href="javascript:;" class="grey s_manage_folder" fid="', obj.fid, '">', obj.name, '</a></td><td>', obj.total, '</td><td>', obj.size, '</td><td>', obj.operate, '</td></tr>'].join('');
		};
		ret.folders.each(function(item) {
			var _fid = item.folder_id,
			_is_pop = false;
			if(_fid == -2 || _fid <= -5) return false;
			var _psn = '';
			if (_fid <= 16) {
				var _clr = '&nbsp;';
				if (_fid == 4 || _fid == 5) {
					_clr = '<a href="javascript:;" hidefocus="true" class="s_manage_clearfolder" fid="' + item.folder_id + '">[清空]</a>';
				}
			} else {
				var _clr = '&nbsp;';
				_psn = 'personal';
				if(IsEmail(item.name, false)) {
					_is_pop = true;
					_clr = '<a href="javascript:;" class="s_manage_pop" hidefocus="true">[管理]</a>';
				} else {
					_clr = '<a href="javascript:;" fid="'+ item.folder_id +'" class="s_manage_change" hidefocus="true">[重命名]</a>&nbsp;&nbsp;<a href="main#createFolderList" class="s_manage_delete" fid="'+ item.folder_id +'" hidefocus="true">[删除]</a>';
				}
			}
			if (_is_pop) {
				_content_pop.push(_folder_item({
					cname: _psn,
					fid: _fid,
					name: item.name,
					total: item.total,
					size: strfsize(item.size),
					operate: _clr
				}));
			} else {
				_content.push(_folder_item({
					cname: _psn,
					fid: _fid,
					name: item.name,
					total: item.total,
					size: strfsize(item.size),
					operate: _clr
				}));
			}
			/*
 else if (tmp.folder_id == 4 || tmp.folder_id == 5) {
 if (tmp.total == 0) {
 data['operations'] = '';
 } else {
 data['operations'] = '<a href="main#createFolderList" hidefocus="true" class="s_manage_clearfolder" fid="'+ tmp.folder_id +'">[清空]</a>';
 }
 htmlString += t.evaluate(data);
 }
 
			else 
				if (IsEmail(tmp.name, false)) {
					data['operations'] = '<a href="main" class="s_manage_pop" hidefocus="true">[管理]</a>';
					popFolderStr += t2.evaluate(data);
				}
				else {
					data['operations'] = '<a href="main#createFolderList" fid="' + tmp.folder_id + '" class="s_manage_change" hidefocus="true">[重命名]</a>&nbsp;&nbsp;<a href="main#createFolderList" class="s_manage_delete" fid="' + tmp.folder_id + '" hidefocus="true">[删除]</a>';
					htmlString += t2.evaluate(data);
				}
			*/
		});
		_content = _content.concat(_content_pop);
		var data = {};
		data['rate_size'] = _rate;
		data['total_mail'] = ret.totalMail;
		data['size_status'] = _status;
		data['folder_item'] = _content.join('');
		
		/*
        var mailStatus = new Template(mailStatusTemplate);
        var mailStatusData = {};
        mailStatusData['totalMail'] = cont.totalMail;
        mailStatusData['totalSize'] = mailContentTotalSize > cont.totalSize ? strfsize(cont.totalSize) : strfsize(mailContentTotalSize);
        mailStatusData['totalQuota'] = G.isMobileUser()?"无限容量":strfsize(mailContentTotalSize);
        mailStatusData['remainSize'] = parseFloat(strfsize(cont.totalSize));
        // $('mail_info').innerHTML = mailStatus.evaluate(mailStatusData);
        var htmlString = folderDetailTable + folderDetailTitle;
        var t = new Template(folderDetailTemplate);
        var t2 = new Template(folderDetailTemplate2);
        var folderDetails = cont.folders;
        var popFolderStr = '';
*/
		try {
			// 更新会话底下的列表目录缓存
			mailConference.F = cont;
			mailConference._folder();
		} catch(e) {}
        try{
            // 将新建改成密码锁
            FolderList = folderDetails;
            mailfolder.initEvent();
        }catch(e){}
		
		
		/*
        for (var indexer = 0; indexer < folderDetails.length; indexer++) {
            var tmp = folderDetails[indexer];
            var data = {};
			if(tmp.folder_id == -2) continue;
            data['id'] = tmp.folder_id;
            data['name'] = tmp.name;
            data['size'] = strfsize(tmp.size);
            data['mailCount'] = tmp.total;
            if (tmp.folder_id <= 16 && tmp.folder_id != 4 && tmp.folder_id != 5) {
                data['operations'] = '&nbsp;';
                htmlString += t.evaluate(data);
            } else if (tmp.folder_id == 4 || tmp.folder_id == 5) {
                if (tmp.total == 0) {
                    data['operations'] = '';
                } else {
                        data['operations'] = '<a href="main#createFolderList" hidefocus="true" class="s_manage_clearfolder" fid="'+ tmp.folder_id +'">[清空]</a>';
                }
                htmlString += t.evaluate(data);
            } else if (IsEmail(tmp.name, false)) {
               	data['operations'] = '<a href="main" class="s_manage_pop" hidefocus="true">[管理]</a>';
               	popFolderStr += t2.evaluate(data);
            } else {
            	data['operations'] = '<a href="main#createFolderList" fid="'+ tmp.folder_id +'" class="s_manage_change" hidefocus="true">[重命名]</a>&nbsp;&nbsp;<a href="main#createFolderList" class="s_manage_delete" fid="'+ tmp.folder_id +'" hidefocus="true">[删除]</a>';
            	htmlString += t2.evaluate(data);
            }
        }
        */
		DOM.newFolderList.innerHTML = new Template(newFolderListTemplate).evaluate(data);
		/*
        htmlString += popFolderStr + '</table>';
        var _fdd = $('folderDetailDIV'), _nmf = $('nmf');
        _fdd.innerHTML = htmlString;
        _nmf.innerHTML = createNewFolderTemplate;
        _nmf.hide();
        try {
            if (!is_add) {
                _nmf.style.display = 'none';
            }
            else {
                _nmf.style.display = '';
            }
            var _t = setTimeout(function(item){
                clearTimeout(_t);
                _t = null;
                $('newFolderName').value = '';
            }, 10);
        } 
        catch (e) {
        }
        */
		addAjaxHistory("createFolderList", "changePanel('newFolderList', null, true)", "自建文件夹", is_rsh);
    },

	// 创建新文件夹
    createNewFolder: function(){
        if (global_flag) return;
        var _fn = $('newFolderName');
        var nfn = toTrimDBC(_fn.value.strip());
        if (nfn.blank()) {
            _dialog.alert({
                info: '文件夹名称不能为空！'
            });
            _fn.focus();
            return;
        }
        if (nfn.include(' ')) {
            _dialog.alert({
                info: '文件夹名称不能含空格！'
            });
            _fn.focus();
            return;
        }
        if (mailAddressClass._check_length(nfn) > 10) {
            _dialog.alert({
                info: '文件夹名称太长！'
            });
            _fn.focus();
            return;
        }
        if (!checkSpecial(nfn)) {
            _fn.focus();
            return;
        }
        for (var i = 0,len = FolderList.length;i < len; i++) {
            if (nfn == FolderList[i].name) {
                _fn.focus();
                _dialog.alert({
                    info: '您创建的文件夹名称重复，请换个名称重新创建！'
                });
                return;
            }
        }
        var params = {
            name: nfn
        };
        if (!this.isChangeFolderName) {
            folder_create(params, this.createNewFolderCallBack.bind(this), this._createFolderFailure.bind(this));
        }
        else {
            this.changeNewFolderName(this.renameFolderId, nfn);
        }
    },

    createNewFolderCallBack: function(ret){
        if (ret.is_success) {
            this.clearNewFolderName();
            this.getMailCount(null, function(){
                this.initFolderDetails();
            }.bind(this));
        } else {
            $('newFolderName').focus();
            _dialog.alert({
                info: '您创建的文件夹名称重复，请换个名称重新创建！'
            });
        }
    },

	// 创建文件夹失败回调函数
	_createFolderFailure: function() {
		_dialog.alert({info: '由于网络原因，创建文件夹失败！'});
	},
	clearNewFolderName: function() {
		$('newFolderName').value = '';
		// $('nmf').hide();
	},
	
    clearTrash: function(_folder_id){
		var self = this;
        var confunc = function(){
            var params = {
                src: _folder_id,
                dest: -1,
                method: 1,
				oclear: 1
            };
            mail_move(params, self._clearTrashCallBack.bind(self, _folder_id));
        };
        _dialog.confirm({
            info: '你确定删除邮件夹中的所有邮件吗？',
            click: function(){
                confunc();
            }
        });
        return;
    },

    _clearTrashCallBack: function(_folder_id, ret){
        if (_folder_id == 4 || _folder_id == 5) {
			// 清空列表页面缓存
			this.clearListCache();
            messageInfo = '邮件夹清空成功！';
            global_flag = false;
            var f_id = _folder_id;
            this.getMailCount(null, function(){
                var id = f_id;
                changePanel('mailList', id);
            });
        }
    },
	
    getMailListFolderlist: function(){
        var l = [], self = this;
        FolderList.each(function(item){
            if (item.folder_id != self.currentFolder && item.folder_id != -2 && item.folder_id != 2 && item.folder_id != 3 && item.folder_id != 4 && item.folder_id != 5 && item.folder_id > -5) {
                l.push({
                    text: item.name,
                    onclick: function(){
                        self.moveMailTo(item.folder_id);
                        return false;
                    }
                });
            }
        });
        return l;
    },

    check: function(){
        if ($('checkbox').checked) {
            $('checkbox').checked = false;
            _dialog.confirm({
                info: '您的邮箱将只能接收您的白名单列表中的邮箱地址发来的邮件，您确定此操作吗？',
                click: function(){
                    $('checkbox').checked = true;
                }
            });
        }
    },
	
    setStar: function(obj, mailid, starflag, f){
        // f: 如果参数被设置，那么表示从读信页面中设置的星标，此时只需要操作缓存就行了
        if (!f) {
			if(this.multiStar.timer) {
				this.stopStar();
				try {
					if (mailid != this.multiStar.id) {
						this.setStarClass(this.multiStar.imgel, this.multiStar.star[0]);
						// this.multiStar.imgel.src = MailConst.ALL + this.multiStar.img[0];
						this.multiStar.imgel.title = this.multiStar.title[0];
						this.multiStar.subel.style.color = this.multiStar.color[0];
					}
				} catch(e) {}
			}
            starflag = (parseInt(starflag) + 1) % 6;
            var params = {
                id: mailid,
                method: 2,
                star: starflag
            };
            mailStarList._opt_id = starflag;
            //mail_change_star(params);
            mail_change_star(params, mailStarList.update_folder_cache);
            this.setStarMailCache(mailid, starflag);
        }
		try {
			this.setStarClass(obj, this.multiStar.star[starflag]);
			obj.title = this.multiStar.title[starflag];
			obj.setAttribute('level', starflag);
			var _sub = obj.parentNode.nextSibling.firstChild;
			_sub.style.color = this.multiStar.color[starflag];
		} catch(e) {}
		try {
			PROFILE.usestar = 1;
		} catch(e) {}
    },
	
	// 设置信件的已读未读
    setRead: function(readflag){
        var _mails = this.getSelectMailList().obj;
        if (_mails == null || _mails.length == 0) {
            _dialog.alert({
                info: '请选择您要操作的邮件'
            });
            return;
        }
        this.MarkMails = [];
        _mails.each(function(mail){
            if (!readflag && mail.have_read == true) {
                this.MarkMails.push(mail.rowid);
                $('tr_' + mail.rowid).addClassName('noread');
                try {
                    this.changeFolderListMarkUnread(this.currentFolder, false);
                } catch (e) {
				}
                // this.refreshFolderListNewMail();
            } else if (readflag && mail.have_read == false) {
                this.MarkMails.push(mail.rowid);
                $('tr_' + mail.rowid).removeClassName('noread');
                try {
                    this.changeFolderListMarkUnread(this.currentFolder, true);
                } catch (e) {
				}
                // this.refreshFolderListNewMail();
            }
            this.setReadCache(mail.rowid, readflag);
            this.checkBoxThis($('tr_' + mail.rowid).getElementsByTagName('input')[0], mail.rowid, false);
        }.bind(this));
		this.refreshFolderListNewMail();
        
        //判断是否选择全选
        if ($('selectAllBoxID').checked) {
            $('selectAllBoxID').checked = false;
        }
        
        var _f = readflag == 0 ? 5 : 0;
        var params = {
            id: this.MarkMails,
            method: _f
        };
        // mail_change_read(params,setReadCallBack);
        mail_move(params, this.setReadCallBack.bind(this));
    },

    setReadCallBack: function(ret){
        if (this.currentFolder == -2) {
            // 计算当前删除的内容是否从最后一页删除
            this.totalUnread = 0;
            FolderList.each(function(item){
                if (item.folder_id == 2 || item.folder_id == 3 || item.folder_id == 4) 
                    return;
                this.totalUnread += item.unread;
            }.bind(this));
            //计算一共几页,页面是从0开始计算
            var mp = this.totalUnread % PAGE_CAPACITY > 0 ? parseInt(this.totalUnread / PAGE_CAPACITY) : this.totalUnread / PAGE_CAPACITY;
            if (mp == this.currentPage && this.MarkMails.length == this.totalUnread % PAGE_CAPACITY) {
                this.currentPage = mp - 1;
            }
        }
        //判读未读邮件箱的操作，刷新页面
        if (this.currentFolder == -2 || this.currentFolder > 16) {
        	this.getMailPage(this.currentFolder, this.currentPage, function(ret){
                this.getMailPageCallback(ret);
                folder_detail({}, this._getMailCountCallBack.bind(this));
            }.bind(this));
        }
        this.MarkMails = [];
    },
	
	// 标记已读未读
    checkBoxThis: function(checkboxElement, id, is_unead){
        if (checkboxElement.checked) {
            $('tr_' + id).style.backgroundColor = '';
            checkboxElement.checked = false;
        }
        _currentPageFolderList.each(function(item){
            if (item.id == id) 
                item.checked = false;
        });
    },


	// 标记已读未读
    getMarkReadList: function(){
		var self = this;
        var draplist = [{
            text: '已读',
            onclick: function(){
                self.setRead(true);
                return false;
            }
        }, {
            text: '未读',
            onclick: function(){
                self.setRead(false);
                return false;
            }
        }];
        return draplist;
    },

	//设置标志已读未读状态的缓存
    setReadCache: function(mail_id, read_level){
		_currentPageFolderList && Object.isArray(_currentPageFolderList) && _currentPageFolderList.each(function(item){
            if (mail_id == item.rowid) {
                item.have_read = read_level;
                var _mail_item = $('tr_' + item.rowid);
                try {
                    if (_mail_item) 
                        read_level ? _mail_item.removeClassName('noread') : _mail_item.addClassName('noread');
                } catch (e) {}
            }
        });
        if (!this.mailListCache['inbox' + this.currentFolder] || this.mailListCache['inbox' + this.currentFolder].length == 0) return;
        try {
			this.mailListCache['inbox' + this.currentFolder].each(function(item){
				if (item) {
					item.each(function(_item){
						if (mail_id == _item.rowid) {
							_item.have_read = read_level;
						}
					});
				}
			});
		} catch(e) {}
    },

	//设置已读未读状态时动态改变右侧邮件列表数目
	//is_unread false 未读  true 已读
    changeFolderListMarkUnread: function(folder_id, is_unread){
		var _i_read = false;
		FolderList.each(function(item) {
			try {
				if (item.folder_id == folder_id) {
					var mc = this.mailListCache['inbox' + folder_id];
					if (is_unread) {
						// FolderList.totalUnread--;
						item.unread--;
						if (mc && mc.length > 0) {
							mc.each(function(_item){
								if (typeof _item.unread == 'number') 
									_item.unread--;
							});
						}
					} else {
						// FolderList.totalUnread++;
						item.unread++;
						if (mc && mc.length > 0) {
							mc.each(function(_item){
								if (typeof _item.unread == 'number') 
									_item.unread++;
							});
						}
					}
				}
				else 
					if (item.folder_id == -2 && !_i_read) {
						is_unread ? item.unread-- : item.unread++;
					}
			} catch(e) {}
		}.bind(this));
    },
	
	// 操作读邮件，星标的cache
    setReadMailCache: function(mail_id) {
        if (this.currentFolder == -2) {
            if (this._setReadMailCache(1, mail_id) || this._setReadMailCache(5, mail_id) || this._setReadMailCache(4, mail_id)) 
                return;
        }
        if (!this.mailListCache['inbox' + this.currentFolder] || this.mailListCache['inbox' + this.currentFolder].length == 0) 
            return;
        this._setReadMailCache(this.currentFolder, mail_id);
    },

    _setReadMailCache: function(current_folder, mail_id) {
        var is_set = false;
        var folder_id = 0;
        var _a = this.mailListCache['inbox' + current_folder];
        _a && _a.length > 0 &&
        _a.each(function(item){
            if (item) {
                item.each(function(_item){
                    if (mail_id == _item.rowid && !_item.have_read) {
                        _item.have_read = 1;
                        is_set = true;
                        folder_id = _item.folder;
                    }
                });
            }
        });
        return is_set;
    },

    setStarMailCache: function(mail_id, star_level){
        if (!this.mailListCache['inbox' + this.currentFolder] || this.mailListCache['inbox' + this.currentFolder].length == 0) return;
        this.mailListCache['inbox' + this.currentFolder].each(function(item){
            if (item) {
                item.each(function(_item){
                    if (mail_id == _item.rowid) {
                        _item.star = star_level;
                        var _el = $('tr_' + mail_id);
                        var _s = _el && _el.getElementsByTagName('td');
                        try {
                            this.setStar(_s[4].firstChild, mail_id, star_level, true);
                        } catch (e) { }
                    }
                }.bind(this));
            }
        }.bind(this));
        try {
            mailRead && mailRead.readMailCache['mail_' + mail_id] && (mailRead.readMailCache['mail_' + mail_id].star = star_level);
        } catch (e) {}
    },

	// 设置已回复，转发的缓存
    setMiscMailCache: function(mail_id, type){
        if (!this.mailListCache['inbox1'] || this.mailListCache['inbox1'].length == 0) return;
        this.mailListCache['inbox1'].each(function(item){
            if (item) {
                item.each(function(_item){
                    if (mail_id == _item.rowid) {
                        _item[type] = 1;
                    }
                });
            }
        });
		this.refreshListFlag = true;
    },

    preLoadedMailList: function(current_page, current_folder){
        current_folder = current_folder ? current_folder : (this.currentFolder != 0 ? this.currentFolder : 1);
        var startIndex = current_page * PAGE_CAPACITY;
        if (isNaN(startIndex) || startIndex < 0) {
            startIndex = 0;
        }
        if (isNaN(PAGE_CAPACITY) || PAGE_CAPACITY < 0) {
            PAGE_CAPACITY = 20;
        }
        var params = {
            folder_id: current_folder,
            start: startIndex,
            length: PAGE_CAPACITY
        };
		try {
			Object.extend(params, this._sort);
		} catch(e) {}
        var _list = this.mailListCache['inbox' + current_folder] ? this.mailListCache['inbox' + current_folder][current_page] : false;
		var _callback = arguments[2];
        if (!_list) {
            folder_list(params, function(ret){
                this.mailListCache['inbox' + current_folder][current_page] = ret;
				if(_callback) {
					_callback(ret);
				}
            }.bind(this));
        }
    }
};
var mailList = new MailList();
